import { ExceptionFilter, Catch, ArgumentsHost } from '@nestjs/common';
import { Response } from 'express';
import { HttpRequestException } from 'src/models/http-request-exception';

@Catch(HttpRequestException)
export class HttpBadRequestExceptionFilter implements ExceptionFilter {
  catch (exception: HttpRequestException, host: ArgumentsHost) {
    const ctx = host.switchToHttp();
    const response = ctx.getResponse<Response>();

    response.status(exception.getStatusCode()).json(exception.getHttpResponse());
  }
}
